﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Cloak.Mvp.Autofac
{
	/// <summary>
	/// Extension methods for appending named and keyed presenters to view presentations
	/// </summary>
	public static class ViewPresentationAppendExtensions
	{
		/// <summary>
		/// Creates a new presentation by appending the specified named presenter
		/// </summary>
		/// <param name="viewPresentation">The presentation which serves as the base for the new one</param>
		/// <param name="type">The type of presenter to append</param>
		/// <param name="name">The name of the presenter to append</param>
		/// <returns>A new presentation with the specified presenter name appended</returns>
		public static ViewPresentation WithNamedPresenter(this ViewPresentation viewPresentation, Type type, string name)
		{
			Contract.Requires(viewPresentation != null);

			return viewPresentation.WithPresenters(new NamedPresenterReference(type, name));
		}

		/// <summary>
		/// Creates a new presentation by appending the specified keyed presenter
		/// </summary>
		/// <param name="viewPresentation">The presentation which serves as the base for the new one</param>
		/// <param name="type">The type of presenter to append</param>
		/// <param name="key">The key of the presenter to append</param>
		/// <returns>A new presentation with the specified presenter name appended</returns>
		public static ViewPresentation WithKeyedPresenter(this ViewPresentation viewPresentation, Type type, object key)
		{
			Contract.Requires(viewPresentation != null);

			return viewPresentation.WithPresenters(new KeyedPresenterReference(type, key));
		}
	}
}